home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_devices / rkrm_devices.lha / Resources / Read_Potinp.c < prev   
C/C++ Source or Header  |  1992-09-03  |  3KB  |  111 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  *****************************************************************************
  27.  *
  28.  *
  29.  * Read_Potinp.c
  30.  *
  31.  * An example of using the potgo.resource to read pins 9 and 5 of
  32.  * port 1 (the non-mouse port).  This bypasses the gameport.device.
  33.  * When the right or middle button on a mouse plugged into port 1 is pressed,
  34.  * the read value will change.
  35.  *
  36.  * Use of port 0 (mouse) is unaffected.
  37.  *
  38.  * Compile with SAS 5.10  lc -b1 -cfistq -v -y -L
  39.  *
  40.  * Run from CLI only
  41.  */
  42.  
  43. #include <exec/types.h>
  44. #include <exec/memory.h>
  45. #include <dos/dos.h>
  46. #include <resources/potgo.h>
  47. #include <hardware/custom.h>
  48.  
  49. #include <clib/exec_protos.h>
  50. #include <clib/potgo_protos.h>
  51.  
  52. #include <stdio.h>
  53.  
  54. #ifdef LATTICE
  55. int CXBRK(void) {return(0);}  /* Disable SAS Ctrl-C checking */
  56. int chkabort(void) { return(0); }  /* really */
  57. #endif
  58.  
  59. struct PotgoBase *PotgoBase;
  60. ULONG potbits;
  61. UWORD value;
  62.  
  63. #define UNLESS(x) if(!(x))
  64. #define UNTIL(x)  while(!(x))
  65.  
  66. #define OUTRY 1L<<15
  67. #define DATRY 1L<<14
  68. #define OUTRX 1L<<13
  69. #define DATRX 1L<<12
  70.  
  71. extern struct Custom far custom;
  72.  
  73. void main(int argc,char **argv)
  74. {
  75. UNLESS (PotgoBase=(struct PotgoBase *)OpenResource("potgo.resource"))
  76.         return;
  77.  
  78.  
  79. potbits=AllocPotBits(OUTRY|DATRY|OUTRX|DATRX);
  80.  
  81. /* Get the bits for the right and middle mouse buttons on the alternate mouse port. */
  82.  
  83. if (potbits != (OUTRY|DATRY|OUTRX|DATRX))
  84.     {
  85.     printf("Pot bits are already allocated! %lx\n",potbits);
  86.     FreePotBits(potbits);
  87.     return;
  88.     }
  89.  
  90. /* Set all ones in the register (masked by potbits) */
  91. WritePotgo(0xFFFFFFFFL,potbits);
  92.  
  93. printf("\nPlug a mouse into the second port.  This program will indicate when\n");
  94. printf("the right or middle button (if the mouse is so equipped) is pressed.\n");
  95. printf("Stop the program with Control-C. Press return now to begin.\n");
  96.  
  97. getchar();
  98.  
  99. UNTIL (SIGBREAKF_CTRL_C & SetSignal(0L,0L))
  100.       /* until CTRL-C is pressed */
  101.       {
  102.       /* Read word at $DFF016 */
  103.         value = custom.potinp;
  104.  
  105.       /* Show what was read (restricted to our allocated bits) */
  106.       printf("POTINP = $%lx\n",value & potbits);
  107.       }
  108.  
  109. FreePotBits(potbits);
  110. }
  111.